/*
 * Copyright 2017-8-30 13:56:26 The JA-SIG Collaborative. All rights reserved.
 * distributed with thi file and available online at
 */
package com.lap.scp.admin.ao.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.lap.scd.commons.ao.AbstractAO;
import com.lap.scd.commons.constant.RespCode;
import com.lap.scd.commons.page.Page;
import com.lap.scd.commons.page.PageResult;
import com.lap.scd.commons.page.PageUtils;
import com.lap.scd.commons.result.Resp;
import com.lap.scp.admin.ao.AccessLogsAO;
import com.lap.scp.admin.core.AccessLogsManager;
import com.lap.scp.admin.domain.AccessLogsDO;
import com.lap.scp.admin.query.AccessLogsQueryDO;

/**
 * <pre>
 * 日志访问对象应用
 * </pre>
 * 
 * @author 系统自动生成 Exp
 * @Date 2017-8-30 13:56:26
 * @since 1.0
 */
@Service("accessLogsAO")
public class DefaultAccessLogsAO extends AbstractAO implements AccessLogsAO {

	@Resource
	private AccessLogsManager accessLogsManager;

	@Override
	public Resp<Integer> deleteById(int accessLogsId) {
		Resp<Integer> result = new Resp<>();
		try {
			int flag = accessLogsManager.deleteById(accessLogsId);
			result.setData(flag);
		} catch (Exception e) {
			result.putMsg(RespCode.Error, super.getMsg("505", new String[] { e.getLocalizedMessage() }));
			writeLog(accessLogsId, e);
		}
		return result;
	}

	@Override
	public Resp<AccessLogsDO> insertAccessLogs(AccessLogsDO accessLogsDO) {
		Resp<AccessLogsDO> result = new Resp<>();
		try {
			accessLogsManager.insertAccessLogs(accessLogsDO);
			result.setData(accessLogsDO);
		} catch (Exception e) {
			result.putMsg(RespCode.Error, super.getMsg("505", new String[] { e.getLocalizedMessage() }));
			writeLog(accessLogsDO, e);
		}
		return result;
	}

	@Override
	public PageResult<AccessLogsDO> queryPage(Page page, AccessLogsQueryDO accessLogsQueryDO) {
		PageResult<AccessLogsDO> pr = new PageResult<AccessLogsDO>();
		try {
			List<AccessLogsDO> list = accessLogsManager.queryPage(page, accessLogsQueryDO);

			PageUtils.copyPage(pr, page);
			pr.setData(list);
		} catch (Exception e) {
			writeLog(new Object[] { page, accessLogsQueryDO }, e);
		}
		return pr;
	}

}
